package com.ypinkj.app.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ypinkj.app.entity.UResumeCertificate;
import com.ypinkj.app.entity.UResumeEducation;
import com.ypinkj.app.entity.UResumeExperience;
import com.ypinkj.app.mapper.UResumeEducationMapper;
import com.ypinkj.app.utils.resultutils.Result;
import com.ypinkj.app.utils.resultutils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 *  教育背景
 * </p>
 *
 * @author LF
 * @since 2020-09-29
 */
@Api(tags = "教育背景")
@RestController
@RequestMapping("/u-resume-education")
public class UResumeEducationController {

    @Autowired
    UResumeEducationMapper resumeEducationMapper;

    @ApiOperation(value = "保存")
    @PutMapping
    public Result save(@RequestBody UResumeEducation resumeEducation) {
        String id = resumeEducation.getId();
        if (id==null) {
            int i = resumeEducationMapper.insert(resumeEducation);
            return i > 0 ? ResultUtil.success(resumeEducation) : ResultUtil.errorMsg();
        }else {
            int i = resumeEducationMapper.UpdateUResumeWorkById(resumeEducation);
            return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
        }
    }

    @ApiOperation(value = "列表")
    @GetMapping
    public Result getList(String userid){
        wrapper.eq(UResumeEducation::getUserid,userid);
        List<UResumeEducation> list = resumeEducationMapper.selectList(wrapper);
        return list.size()>0 ?ResultUtil.success(list) : ResultUtil.errorMsg();
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping
    public Result deleteById(String id){
        int i = resumeEducationMapper.deleteById(id);
        return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
    }

    @ApiOperation(value = "根据id修改")
    @PostMapping
    public Result updateById(UResumeEducation resumeWork){
        int i = resumeEducationMapper.UpdateUResumeWorkById(resumeWork);
        return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
    }

    private static LambdaQueryWrapper<UResumeEducation> wrapper = new LambdaQueryWrapper<>();
}
